package com.sq.partner.manager.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;

import com.sq.partner.manager.dao.ICoreDeptDao;
import com.sq.partner.manager.dao.ITradProtocolValueDao;
import com.sq.partner.manager.mybatis.model.CoreDept;
import com.sq.partner.manager.mybatis.model.TradProtocolValue;
import com.sq.partner.manager.service.NoCarProtocolService;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.excel.ExcelEntity;
import com.sq.partner.manager.util.excel.ExportExcelBuilderTool;

@Service
public class NoCarProtocolServiceImpl implements NoCarProtocolService{
	
	@Resource
	ICoreDeptDao coreDeptDao;
	@Resource
	ITradProtocolValueDao tradProtocolValueDao;
	@Resource
	ExportExcelBuilderTool exportExcelBuilderTool;

	@Override
	public Page<Map<String, Object>> queryTradProtocolValuePage(
			Page<Map<String, Object>> page, Map<String, Object> map)
			throws Exception {
		// TODO Auto-generated method stub
		return tradProtocolValueDao.queryTradProtocolValuePage(page, map);
	}

	@Override
	public Map<String, Object> queryCJBTradProtocolValueByProtocolNo(
			String protocolNo) throws Exception {
		// TODO Auto-generated method stub
		return tradProtocolValueDao.queryCJBTradProtocolValueByProtocolNo(protocolNo);
	}
	
	//生成协议编号
	@Override
	public String queryMaxSerialNumber(Map<String, Object> map)
			throws Exception {
		// TODO Auto-generated method stub
		return tradProtocolValueDao.queryMaxSerialNumber(map);
	}

	@Override
	public void addTradProtocolValue(List<TradProtocolValue> lists,
			Map<String, Object> map) throws Exception {
		tradProtocolValueDao.addTradProtocolValue(lists, map);
	}

	@Override
	public void updateTradProtocolValue(List<TradProtocolValue> lists,
			Map<String, Object> map) throws Exception {
		// TODO Auto-generated method stub
		tradProtocolValueDao.updateTradProtocolValue(lists, map);
	}

	@Override
	public void delTradProtocolValue(String protocolNo) throws Exception {
		// TODO Auto-generated method stub
		tradProtocolValueDao.delTradProtocolValue(protocolNo);
	}

	@Override
	public void buildExcel(HttpServletResponse response, Map<String, Object> map) throws Exception {
		ExcelEntity excel = new ExcelEntity();
		List<Map<String,Object>> results = tradProtocolValueDao.queryProtocolExcel(map);
		excel.setResults(results);
		excel.setFileName("协议明细");
		excel.setTitles("延保协议编号,业务范围,第三方延保服务机构,协议开始日期,协议结束日期,产品名称,延保保障范围,延长保修期限（月）,保修期限-总里程（质保里程+延保里程）（公里）,车辆使用性质,厂家质保期限（月）,厂家质保里程数（公里）,投保人名称,投保人地址,被保险人名称,被保险人地址,被保人类型,投保人电话,被保险人电话,证件类型,经营许可证号,被保人有效身份证明号,洗钱风险,市场费用率,是否共保,归属渠道,渠道类型,业务来源,机构部门,业务员,销售团队,服务代码,代理人,合作协议号,固定特别约定");
		excel.setTitleKeys("PROTOCOL_NO,BUSI_SCOPE_NAME,EX_DEPT,PRTL_START_DATE,PRTL_END_DATE,PLAN_NAME,EX_SCOPE,EX_WARRPRID,MAX_MILEAGE,VEHICLE_USE_PROPERTY,VENDER_WARRANTY_PERIOD,VENDER_WARRANTY_MILEAGE,TBR_NAME,TBR_ADDR,BBR_NAME,BBR_ADDR,BBR_TYPE_NAME,TBR_TEL,BBR_TEL,ID_TYPE_NAME,BUSINESS_LICENSE_NO,ID_NO,MONEY_LAUNDERING_RISK,MARKET_EXPENSE_RATIO,IS_POOL,CHANNEL_CODE,CHANNEL_TYPE,NEW_BSNS_TYPE,DEPT_CNAME,EMP_NAME,TEAM_NAME,SERVICE_CODE,AGENT_NO,PROTOCOL_NO1,SPECIAL_ARRAN");
		excel.setColumns("32,10,23,16,16,60,16,24,56,16,24,29,15,40,16,40,15,15,15,15,15,25,15,15,10,10,10,10,60,10,80,15,15,18,150");
		exportExcelBuilderTool.buildExcel(response,excel);
	}

	@Override
	public List<CoreDept> queryPrivilegeBranch(String deptCodeStr)
			throws Exception {
		
		return coreDeptDao.queryDeptList(deptCodeStr);
	}
	
}
